/**
 * 应付账户支付
 */
/**
 * 表单自定义控制器
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http) {
	$scope.bindBtn = function(event) {
		switch(event){
			case 'event-to-add': // 新增
			{
				var needPayAccountCode = $scope.valueMap['needPayAccountCode'];//应付账户编码
				if(needPayAccountCode==undefined || needPayAccountCode==null || needPayAccountCode==''){
					layer.msg("请先选择应付账户!");
					return;
				}

				//layui.YsModal.init({modalKey: 'TCW_NeedPayLedgerDetail', type: 'checkbox', uniqueKey: 'id', parentObj: t.c.subGridObj, selectedData: selectedDatas, extraData:{}, conditionsDefault: [{code: 'needPayAccountCode', value: needPayAccountCode}]});


				var listUkey = [];
				for(var i=0;i<$scope.subGrid.sonlist.length;i++){
					var data = $scope.subGrid.sonlist[i];
					listUkey.push(data.id);
				}
				$scope.showModalCheckBox('TCW_NeedPayLedgerDetail', 'id', listUkey);
				// TODO
				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}


		};
	}

}



/*
* 子列表控制器
*/
app.controller('subGridCtrl', ['$scope', '$http', function SubGridController($scope, $http){
	//多选框回调
	$scope.checkbox.afterSelectDatas = function(rowsSelected) {
		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			$scope.subGrid.sonlist.push({
				needPayLedgerDetailId: row.id,
				createTime: row.createTime,
				needPayTypeCode: row.needPayTypeCode,
				needPayTypeName: row.needPayTypeName,
				vgsbm: row.vgsbm,
				vgsjc: row.vgsjc,
				vjylx: row.vjylx,
				detailName: row.detailName,
				costPrice: row.costPrice,
				quantity: row.quantity,
				totalPrice: row.totalPrice,
				materialRemark: row.remark,
				servicePrice: row.servicePrice,
				payedPrice: row.payedPrice,
				proxyPrice: row.proxyPrice,
				//unpayPrice: (row.costPrice * row.quantity - row.payedPrice),
				unpayPrice:0,
				amount: (row.costPrice * row.quantity).toFixed(2)
			});
		}


	}
}]);
